<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="cn.hit.edu.switter.DatabaseHelper"%>
<%@ page import="java.util.ArrayList"%>
<%@ page import="cn.hit.edu.switter.Message" %>
<%@ page import="cn.hit.edu.switter.Account" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%! private int UserId; %>

<%
	DatabaseHelper db = new DatabaseHelper();
	Integer id = (Integer) session.getAttribute("UserId");

	if (id == null) {
		response.sendRedirect("/Switter_beta/login.html");
	} else {
		UserId = id.intValue();
	}
%>


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" href="base.css" type="text/css" media="screen"
	charset="utf-8" />
<style type="text/css">
body {
	background-color: #E9F0DB;
	background-image: url(http://static.fanfou.com/img/bg/17.png);
	background-repeat: repeat;
	background-position: top left;
	color: #8D7947;
}

a,#sidebar a:hover,.pagination .more:hover,.stamp a:hover,.light .stamp a
	{
	color: #AF838C;
}

a:hover,.light .stamp .reply a {
	background-color: #AF838C;
}

a:hover .label,a.photo:hover img,.stamp a:hover,.light .stamp a {
	border-color: #AF838C;
}

.actions .open-notice:hover {
	color: #AF838C;
}

#sidebar {
	background-color: #F4F8ED;
	border-left: 1px solid #CEDDC2;
}

#sidebar .sect {
	border-top-color: #CEDDC2;
}

#sidebar .stabs {
	border-bottom-color: #CEDDC2;
}

#sidebar .stabs li.current a {
	color: #8D7947;
}

#user_stats li {
	border-left-color: #CEDDC2;
}

#user_stats .count {
	color: #8D7947;
}

#user_stats a:hover .count {
	color: #AF838C;
}

#goodapp span {
	color: #8D7947;
}
</style>
<title>首页_Switter</title>
</head>
<body>
<div id="container" class="newlook">
<div id="header">
<h1><a href="index.jsp"><img src="RESOURCE/switter.png"
	alt="Switter" /><span>首页</span></a></h1>
<div id="navigation" class="ui-roundedbox">
<div class="ui-roundedbox-corner ui-roundedbox-tl">
<div class="ui-roundedbox-corner ui-roundedbox-tr">
<div class="ui-roundedbox-corner ui-roundedbox-bl">
<div class="ui-roundedbox-corner ui-roundedbox-br">
<div class="ui-roundedbox-content">
<ul>
	<li><a href="index.jsp">首页</a></li>
	<li><a href="home.jsp?Id=<%=UserId%>">我的空间</a></li>
	<li><a href="browse.jsp">随便看看</a></li>
	<li><a href="/Switter_beta/settings.jsp">设置</a></li>
	<li><a href="/Switter_beta/logout">退出</a></li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

<table id="columns">
	<tr>
		<td id="main">
		<div id="update">
		<form method="post" action="/Switter_beta/PostMessage" id="message" class="limit">
		<h2>你在做什么？</h2>
		<p><textarea name="content" rows="3" cols="70" class="qs"></textarea>
		</p>

		<div class="act">
		<div class="actpost"><input type="hidden" name="action"
			value="msg.post" /> <input type="hidden" name="in_reply_to_status_id"
			value="" /> <input type="hidden" name="repost_status_id" value="" />
		<input type="hidden" name="token" value="168912a8" /> <img
			class="loading" src="http://static.fanfou.com/img/ajax-indicator.gif" /><input
			type="submit" class="formbutton" title="按Enter键发送消息" value="发送" />
		</div>
		<div class="lastmsg">
		
		<%
					ArrayList<Message> msg = db.fetchMessages(UserId, 10);
					Account owner = db.fetchAccount(UserId);
					//out.println(UserId);
					String latestMsg = "无新消息";
					String avatar = owner.getPicName();
					String nickname_a = owner.getNickname();
					
					if (msg != null && msg.size() > 0) {
					 	latestMsg = msg.get(0).getMsg();
					}
		%>
		<p id="lastmsg-43SZXRMUWqQ"><strong> </strong><span
			class="time" title="" ><%=latestMsg%></span></p>
		</div>
		</div>
		<p class="tip">可以输入 <span class="counter">140</span> 字</p>
		</form>
		</div>
		<div id="content">
		<div id="timeline-head" style="display: none;"></div>
		
		<div id="stream" class="message">
		<ol class="wa solo">
			<%
				if (msg != null) {
					for (int i = 0; i < msg.size(); i++) {
						String details = msg.get(i).getMsg();
			%>
			<li><a href="home.jsp?Id=<%=UserId%>" title="nickname" class="avatar">  <img src="/Switter_beta/Avatars/<%=avatar%>" /></a>
			<a href="home.jsp?Id=<%=UserId%>" class="author"></a><span class="content"><%=details%></span>
			</li>
		<%
			}
			}
		%>
		<%
			ArrayList<Integer> friends = db.fetchFriends(UserId);
			//ArrayList<Account> frList = new ArrayList<Account>();
			
			/*for (int j = 0; j < friends.size(); j++)
				frList.add(db.fetchAccount(friends.get(j)));
			*/
			for (int i = 0; i < friends.size(); i++) {
				ArrayList<Message> msgList = db.fetchMessages(friends.get(i), 10);// 获取好友的消息
				
				Account frAcc = db.fetchAccount(friends.get(i));//获取好友个人资料
				String frAvatar = frAcc.getPicName();
				String frName = frAcc.getNickname();
				int frId = friends.get(i);
				for (int j = 0; j < msgList.size(); j++) {
					String frMsg = msgList.get(i).getMsg();
		%>
			<li><a href="home.jsp?Id=<%=frId%>" title="<%=frName%>" class="avatar">
			  <img src="/Switter_beta/Avatars/<%=frAvatar%>" /></a>
			<a href="home.jsp?Id=<%=frId%>" class="author"></a><span class="content"><%=frMsg%></span>
			</li>
		<%
			}
			}
		%>
		</ol>
		</div>
		
		<div class="pagination"><a id="pagination-more" class="more" href="/home?max_id=DJcYOuzCmJw" onclick="return false;">更多</a></div>
		</div>

		</td>
		<td id="sidebar">
		<div id="user_top"><a href="/johnnyxia"><img
			src="/Switter_beta/Avatars/<%=avatar%> "
			alt="<%=nickname_a%>" /></a>
		<h3><%=nickname_a%></h3>
		</div>
		<!--  
		<ul id="reminder">
			<li><a href="/settings/mobile">绑定手机！</a></li>
		</ul>
		<ul id="user_stats">
			<li><a href="/friends/johnnyxia"><span class="count">2</span>
			<span class="label">我关注的人</span></a></li>
			<li><a href="/followers/johnnyxia"><span class="count">1</span>
			<span class="label">关注我的人</span></a></li>
			<li><a href="/johnnyxia"><span class="count">1</span> <span
				class="label">消息</span></a></li>
		</ul>
		
		<div class="stabs" id="navtabs">
		<ul>
			<li id="navtabs-home" class="current"><a href="/home"><span
				class="label">首页</span></a></li>
			<li><a href="/mentions"><span class="label">@提到我的</span> <span
				class="count">(1)</span></a></li>
			<li><a href="/privatemsg"><span class="label">私信</span> </a></li>
			<li><a href="/favorites/johnnyxia"><span class="label">收藏</span></a></li>
			<li><a href="/album/johnnyxia"><span class="label">照片</span></a></li>
		</ul>
		</div>

		<div id="searchr">
		<form action="http://fanfou.com/search" method="get" id="searchr-form">
		<input type="text" id="searchr-input" name="q" value="" /><input
			type="submit" id="searchr-submit" value="搜索" /></form>
		</div>
		<div id="savedsearchs" class="stabs colltab trendtabs"
			style="display: none;"><b></b>
		<h2>保存的搜索</h2>
		<ul></ul>
		</div>
		-->
		<div class="stabs colltab trendtabs" id="trendtabs"><b
			id="trendicon"></b>
		<h2 id="trendtitle">热门话题</h2>
		<ul id="trendlist">
		<%--
		
		--%>
			<li><a href="" squery="核泄漏|核电站|福岛|女川"><span class="label">核泄露</span></a>
			<div class="spinner"></div>
			</li>
		
		</ul>
		</div>
		<div id="friends" class="colltab"><b></b>
		<h2>我关注的人</h2>
		<ul class="alist">
		
			<%
				
				for (int i = 0; i < friends.size(); i++) {
					int fid = friends.get(i);
					
					Account acc = db.fetchAccount(fid);
				 	if (acc != null) {
						String picName = acc.getPicName();
						String nickname = acc.getNickname();
			%>
					<li><a href="/Switter_beta/home.jsp?Id=<%=fid%>" title="<%=nickname%>">
					<img src="/Switter_beta/Avatars/<%=picName%>" alt="<%=nickname%>" /><span><%=nickname%></span></a></li>
			<%
						}
				}
				
			%>
					</ul>	
					</div> 
		

		<div id="badge-sect" class="sect">
		<h3><a href="/badge">插件</a></h3>
		<p>在你的 Blog 上自动显示你的最新消息</p>
		<p><a href="/badge">&raquo; 试试Switter插件</a></p>
		</div>

		
		</td>
	</tr>
</table>
</div>
</body>
</html>
